package com.gvtv.main.email;

import java.util.List;

import org.joda.time.DateTime;

import com.gvtv.main.execute.ExecuteJob;
import com.gvtv.main.util.Constant;
import com.gvtv.main.util.PropertiesHelper;

public class EmailInfo {

	private String schedulId;
	private List<ExecuteJob> jobs;
	private String emailTos;
	private String emailCcs;
	private String title;
	
	public EmailInfo(){
		
	}
	public EmailInfo(String schedulId, List<ExecuteJob> jobs){
		this(PropertiesHelper.getString("mail.title"), schedulId, jobs, PropertiesHelper.getString("mail.to"), PropertiesHelper.getString("mail.cc"));
	}
	
	public EmailInfo(String title, String schedulId, List<ExecuteJob> jobs){
		this(title, schedulId, jobs, PropertiesHelper.getString("mail.to"), PropertiesHelper.getString("mail.cc"));
	}
	
	public EmailInfo(String title, String schedulId, List<ExecuteJob> jobs, String tos, String ccs){
		this.title = title;
		this.schedulId = schedulId;
		this.jobs = jobs;
		this.emailTos = tos;
		this.emailCcs = ccs;
	}

	public String toEmailContent(){
		StringBuilder sb = new StringBuilder(500);
		//sb.append("<h4 align=\"center\">").append(this.schedulId).append("调度运行情况</h4>");
		if(jobs!=null&&!jobs.isEmpty()){
			sb.append("<TABLE align = \"center\" border = \"1\" cellspacing = \"0\" cellpadding = \"2\" width = \"900\" >");
			sb.append("<tr align = \"center\" > <td> Job ID </td> <td> Job名称 </td> <td> 类型 </td> <td> 状态 </td> <td> 提交时间 </td> <td> 运行时间 </td> <td> 结束时间 </td> </tr>");
			for (ExecuteJob executeJob : jobs) {
				sb.append("<tr align = \"center\" > ");
				sb.append("<td>").append(executeJob.getId()).append("</td>");
				sb.append("<td>").append(executeJob.getJobName()).append("</td>");
				sb.append("<td>").append(executeJob.getJobType()).append("</td>");
				sb.append("<td>").append(executeJob.getJobState()).append("</td>");
				sb.append("<td>").append(new DateTime(executeJob.getSubmitTime().getTime()).toString(Constant.DATETIME_FORMAT)).append("</td>");
				sb.append("<td>").append(new DateTime(executeJob.getStartTime().getTime()).toString(Constant.DATETIME_FORMAT)).append("</td>");
				sb.append("<td>").append(new DateTime(executeJob.getEndTime().getTime()).toString(Constant.DATETIME_FORMAT)).append("</td>");
				sb.append("</tr>");
			}
			sb.append("</TABLE>");
			sb.insert(0, "<h4 align=\"center\">"+this.schedulId+"调度运行情况</h4>");
			
		}
		
		return sb.toString();
	}
	
	public String getSchedulId() {
		return schedulId;
	}

	public void setSchedulId(String schedulId) {
		this.schedulId = schedulId;
	}

	public List<ExecuteJob> getJobs() {
		return jobs;
	}

	public void setJobs(List<ExecuteJob> jobs) {
		this.jobs = jobs;
	}

	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getEmailTos() {
		return emailTos;
	}

	public void setEmailTos(String emailTos) {
		this.emailTos = emailTos;
	}

	public String getEmailCcs() {
		return emailCcs;
	}

	public void setEmailCcs(String emailCcs) {
		this.emailCcs = emailCcs;
	}
	
}
